//
//  ZLTabBar.swift
//  新浪微博
//
//  Created by 朱玉龙 on 9/22/16.
//  Copyright © 2016 朱玉龙. All rights reserved.
//

import UIKit

class ZLTabBar: UITabBar {

    
    
  
    override func layoutSubviews() {
        
        super.layoutSubviews()
        
        let width = UIScreen.main.bounds.width / 5
        
        var index = 0
        
        for subView in subviews {
            
            if subView.isKind(of: NSClassFromString("UITabBarButton")!) {
                
                subView.frame = CGRect(x: CGFloat(index) * width, y: 0, width: width, height: self.bounds.height)
                
                index += index == 1 ? 2 : 1
                
                composeButton.center = CGPoint(x: self.center.x, y: self.bounds.height / 2)
            }
        }
        
    }
    
    lazy var  composeButton:UIButton = {
        
        let button = UIButton()
        
        button.setImage(#imageLiteral(resourceName: "tabbar_compose_icon_add"), for: .normal)
        
        button.setImage(#imageLiteral(resourceName: "tabbar_compose_icon_add_highlighted"), for: .selected)
        
        button.setBackgroundImage(#imageLiteral(resourceName: "tabbar_compose_button"), for: .normal)
        
        button.setBackgroundImage(#imageLiteral(resourceName: "tabbar_compose_button_highlighted"), for: .selected)
        
        button.sizeToFit()
        
        self.addSubview(button)
     
        return button
    }()
    
    
    
}
